package com.example.controller;

import com.example.MyDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/books")
public class BookController {
    //读取yml中的单一数据
    @Value("${country}")
    private String country1;

    @Value("${user1.name}")
    private String name1;

    @Value("${a.b.c.d}")
    private String x;

    @Value("${likes[2]}")
    private String likes1;

    @Value("${users2[0].age}")
    private String age2;

    @Value("${tempDir}")
    private String temp;

    @Autowired
    private Environment environment;

    @Autowired
    private MyDataSource myDataSource;

    @GetMapping
    public String getById() {
        System.out.println("springboot is running......");
        System.out.println("country====>" + country1);
        System.out.println("======>" + name1);
        System.out.println(likes1);
        System.out.println(age2);
        System.out.println(temp);
        System.out.println("======================================================================");
        System.out.println(environment.getProperty("likes[2]"));
        System.out.println(environment.getProperty("country"));
        System.out.println(myDataSource);
        return "springboot is running......";
    }
}
